Skip to content

fix(updater): relaunch desktop shell after update and preserve preflight errors - #1344

Merged
iruriQ merged 1 commit into
mainfrom
fix/updater-restart-desktop-shell-and-preserve-error
Nov 28, 2026
Merged

iruriQ merged 1 commit into
mainfrom
fix/updater-restart-desktop-shell-and-preserve-error

Conversation

@iruriQ

@iruriQ iruriQ commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fix two Rust update/restart bugs reproduced during end-to-end isolated update testing:

  1. P1 — Desktop Shell killed during update and never restarted:
    • services::stop_for_update stopped a running Desktop Shell (desktop-shell-ready.json), but service_update, UpdateRequest, and codexhost-updater only tracked official Codex Desktop ("desktop") and background Web ("web"), leaving Desktop Shell closed permanently after updates.
  2. P2 — Preflight failure errors overwritten during handshake:
    • When codexhost-updater rejected an update in preflight (e.g. npm global prefix mismatch) and wrote a specific actionable error into status-v1.json, active_update.rs and service_update::record_failure overwrote it with the generic "background Updater failed before waiting for Launcher exit" message.

Changes

  • crates/launcher/src/desktop_shell.rs: Add desktop_shell::running(data) sharing live_owner identity verification with stop, plus unit test coverage.
  • crates/launcher/src/service_update.rs:
    • Detect desktop_shell::running(data) in prepare_request / bind_request and set "restart_desktop_shell": true only when active (preserving existing "desktop" / "web" restart_target behavior and official Codex Desktop coexistence).
    • Preserve existing non-empty phase == "failed" errors in record_failure instead of overwriting them.
  • crates/launcher/src/active_update.rs: Parse error in UpdateStatusProbe, propagate specific updater failure messages in wait_for_updater_ready (with a final status re-read after child.try_wait() catches exit to eliminate the exit race), and add regression test preserves_preflight_failure_error_written_by_updater.
  • crates/updater/src/request.rs: Add backward-compatible #[serde(default)] restart_desktop_shell: bool to UpdateRequest and require an explicit absolute data_directory when enabled.
  • crates/updater/src/restart.rs & crates/updater/src/main.rs: Share apply_restart_environment (CODEXHOST_DATA_DIR and CODEXHOST_NPM_*), add detached relaunch_desktop_shell invoking updated codexhost app, and trigger it after writing terminal status-v1.json on both update success and successful service rollback recovery.
  • crates/updater/tests/background_services.rs & crates/launcher/tests/web_service.rs: Add mock integration tests covering Desktop Shell relaunch after update success and rollback recovery, pure-Web non-regression, and restart_desktop_shell handoff propagation.

Visual Changes

No visual changes: native Rust launcher and updater lifecycle/error-preservation fixes only.

Validation

  • cargo fmt --all -- --check: passed (implementation session).
  • cargo test --locked -p codexhost-updater: 45 unit + 4 background_services integration tests passed (implementation session).
  • cargo test --locked -p codexhost-launcher -- active_update service_update web_service host_service desktop_shell: 23 unit tests passed (implementation session).
  • cargo test --locked -p codexhost-launcher --test web_service: 20 integration tests passed (implementation session).
  • pre-commit formatting check: passed.
  • Full-repo lint/typecheck/test delegated to CI per AGENTS.md.

…ght errors

Fixes two Rust update/restart failures reproduced in end-to-end isolated update testing:

1. Preserve Desktop Shell across updates:
   - Detect an active Desktop Shell (desktop-shell-ready.json with live owner) in launcher service_update::prepare_request and pass backward-compatible restart_desktop_shell: true in UpdateRequest (keeping restart_target unchanged for official Codex Desktop and background Web coexistence).
   - After codexhost-updater finishes restoring services and writes terminal status-v1.json (on both update success and successful failure rollback), relaunch the updated Desktop Shell via detached `codexhost app` with CODEXHOST_DATA_DIR and npm runtime env vars preserved.
2. Preserve updater preflight failure errors during handshake:
   - Parse status-v1.json's error field in launcher active_update::wait_for_updater_ready (including a final re-read after child exit to avoid the exit race) and avoid clobbering an already-recorded non-empty failed error in service_update::record_failure.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 新功能
    • 服务更新会根据桌面 Shell 的运行状态,在更新成功或服务恢复后尝试重新启动桌面 Shell。
    • 更新状态为失败时,优先展示 Updater 提供的具体错误信息;缺少有效信息时仍显示通用错误。
  • 改进
    • 更新请求会校验数据目录设置,并在 Shell 运行时纳入相应的重启目标。
    • 服务恢复成功后会记录恢复状态及结果。

本次变更使 Launcher 根据桌面 Shell 的运行状态设置更新请求标记。Updater 在更新成功或服务恢复成功后,可按该标记重新启动桌面 Shell。Launcher 读取失败状态中的错误文本,并保留已有的非空失败信息。

Changes: 桌面 Shell 更新流程

Layer / File(s) Summary
请求标记与 Shell 状态
crates/updater/src/request.rs, crates/launcher/src/desktop_shell.rs, crates/launcher/src/service_update.rs, crates/launcher/tests/web_service.rs
UpdateRequest 新增默认值为 false 的 restart_desktop_shell 字段。Launcher 检查就绪记录对应的进程实例,并据此设置或移除请求标记。测试覆盖不同运行状态及请求组合。
Updater 重启与集成验证
crates/updater/src/restart.rs, crates/updater/src/main.rs, crates/updater/src/install.rs, crates/updater/tests/background_services.rs
Updater 在更新成功,或服务恢复成功后,按请求标记尝试启动桌面 Shell。重启命令设置数据目录和适用的 npm 环境变量。集成测试覆盖安装成功、安装失败后恢复及不重启 Shell 的流程。
失败状态与错误保留
crates/launcher/src/active_update.rs, crates/launcher/src/service_update.rs
Launcher 在 Updater 失败时优先返回状态中的非空错误文本。已有非空失败错误及其时间戳不会被后续失败记录覆盖。

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Launcher
  participant Updater
  participant UpdateStatus
  participant DesktopShellLauncher
  Launcher->>Launcher: 检查桌面 Shell 活动状态并设置重启标记
  Launcher->>Updater: 提交更新请求
  Updater->>UpdateStatus: 写入终态更新状态
  Updater->>DesktopShellLauncher: 标记启用且符合重启条件时启动 app
Loading

Suggested reviewers: bytepioneer-ai, mouzhi

Merge Risk: Minimal · up to c33f6

Updates now relaunch the Desktop Shell after a successful update or a successful service recovery, and the updater's specific preflight error is preserved. The only gap found is a narrow race: a Shell started in the brief window before the update begins stopping services is closed and not restarted, and the user can reopen it. No material merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix(updater): relaunch desktop shell after update and preserve preflight errors”准确概括了两项主要变更:更新后重新启动桌面 Shell,以及保留预检错误。变更集中的 updater 和 launcher 代码与这两项修复一致,因此标题与变更相关。标题较长(79 个字符),但仍清晰、具体。
Description check Passed 描述说明了两个待修复的问题:更新期间桌面 Shell 被停止且未重新启动,以及预检失败时通用错误覆盖了具体错误。描述还列出了各文件的改动、测试与验证结果,与变更集直接相关。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between cfc33ca and c33f63c.

Files selected for processing: 9

  • crates/launcher/src/active_update.rs
  • crates/launcher/src/desktop_shell.rs
  • crates/launcher/src/service_update.rs
  • crates/launcher/tests/web_service.rs
  • crates/updater/src/install.rs
  • crates/updater/src/main.rs
  • crates/updater/src/request.rs
  • crates/updater/src/restart.rs
  • crates/updater/tests/background_services.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

Recent review details

Context from checks skipped due to timeout: 8

  • GitHub Check: CodeRabbit
  • GitHub Check: Check macos-26
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Check Linux ARM64
  • GitHub Check: Static checks
  • GitHub Check: Vitest
  • GitHub Check: Check windows-latest
  • GitHub Check: Web Host tests
Additional context used

Code guidelines: 1

CLAUDE.md — auto-discovered
Path-based instructions: 1

Source excerpt: Rust owns native launch, process management, update installation, and platform integration.

CodeRabbit inference engine (CLAUDE.md)

Files:

  • crates/launcher/src/active_update.rs
  • crates/launcher/src/desktop_shell.rs
  • crates/launcher/src/service_update.rs
  • crates/launcher/tests/web_service.rs
  • crates/updater/src/install.rs
  • crates/updater/src/main.rs
  • crates/updater/src/request.rs
  • crates/updater/src/restart.rs
  • crates/updater/tests/background_services.rs
ast-grep (0.51.3)

crates/launcher/src/active_update.rs

[error] 658-659: Passing non-literal (user-controlled or interpolated) data to a shell invoked via std::process::Command::new("sh"|"bash"|...) with -c allows command injection. Avoid spawning a shell: pass the program and each argument separately to Command::new(program).arg(arg) so the OS never re-parses the string, or strictly allowlist/escape any value that must reach a shell.
Context: std::process::Command::new("/bin/sh")
.args(["-c", &script])
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(command-injection-process-shell-rust)

Additional comments: 1

crates/updater/src/restart.rs: 1

278-279: Functional Correctness

The review concern does not hold for the custom data directory. The app launch path reads CODEXHOST_DATA_DIR from its environment through startup_record::data_directory(), and desktop_shell.rs passes the resolved data directory to the Shell. The restart command therefore does not cause the Shell to open the default data directory. The comment does not identify another defect in lines 278-279.

@iruriQ
iruriQ merged commit 2e9b6bf into main Nov 28, 2026
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants